package HCI.src;

import java.io.IOException;



import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;

public class HCI1Login extends Activity// implements SurfaceHolder.Callback 
{
	static String user="";
    /** Called when the activity is first created. */
     
	Connector a ;
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
         
        	
        	
        
        Button Login = (Button)findViewById(R.id.login);
          
         
        	 Login.setOnClickListener(new View.OnClickListener(){ 
     	    	public void onClick(View view) {
     				Intent switchToRegistration = new Intent(view.getContext(), TabView.class);
     				EditText username = (EditText)findViewById(R.id.UsernameEditText);
     		        EditText password = (EditText)findViewById(R.id.passwordtext);
     		      //  a.run();
     		        a=new Connector("SELECT usr_name FROM user WHERE usr_name ='"+username.getText().toString()+"'"+" and usr_pswd='"+password.getText().toString()+"';");
     		        user = username.getText().toString();
     		        Log.d("hello","i beg you");
     		   //   Thread cThread = new Thread(a);
     		 //     cThread.start();
              String Arr[][]=  a.run();
		       Log.d("hello","i beg you3");

     		      if(Arr!=null){
  
     		     startActivity(switchToRegistration);
 		    	 Toast.makeText(getBaseContext(), "Welcome", Toast.LENGTH_LONG).show();	

     		      }
     		      if(Arr==null)
     		      {
     		    	 Toast.makeText(getBaseContext(), "invalid username or password", Toast.LENGTH_LONG).show();	
     		      }
						// Toast.makeText(getBaseContext(), "invalid username or password", Toast.LENGTH_LONG).show();	
     		      
     		      // cThread.
     		      
     		       
     		     //  
     				/*if(username.getText().toString().equals("fady")&&password.getText().toString().equals("amir")){
     					
     				startActivity(switchToRegistration);
     	    	}*/
              //	Log.d("fadi2",""+a.bool);

					/*if(a.bool.equals("true")){
						startActivity(switchToRegistration);
					   }
					else{
							 Toast.makeText(getBaseContext(), "invalid username or password", Toast.LENGTH_LONG).show();	
						}*/
				
     	    }
     	    	 
        }
        	 ); 
        	
         
        
       
        Button register = (Button)findViewById(R.id.register);
	    register.setOnClickListener(new View.OnClickListener(){ 
	    	public void onClick(View view) {
	    		 
	    		//Connector a = new Connector();
	    		//a.run();
					Log.d("thread","beginn");

             
	    		
				Intent switchToRegistration = new Intent(view.getContext(), register.class);
				
				startActivity(switchToRegistration);
	    	}
	    }
	    	);
	   
    }
    /*	private MediaPlayer mediaPlayer;
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	setContentView(R.layout.main);
    	mediaPlayer = new MediaPlayer();
    	SurfaceView surface = (SurfaceView)findViewById(R.id.surface);
    	SurfaceHolder holder = surface.getHolder();
    	holder.addCallback(this);,l;l;l;l;lkklkl;l;lk
    	holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    	holder.setFixedSize(400, 300);
    	
    	}
    	public void surfaceCreated(SurfaceHolder holder) {
    	try {
    	mediaPlayer.setDisplay(holder);
    	mediaPlayer.setDataSource("file://hitler.mp4");
    	mediaPlayer.prepare();
    	mediaPlayer.start();
    	} 
    	
    	catch (IllegalArgumentException e) {
    	Log.d("MEDIA_PLAYER", e.getMessage());
    	}
    	catch (IllegalStateException e) {
    		Log.d("MEDIA_PLAYER", e.getMessage());
    		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    }
    	


		@Override
		public void surfaceChanged(SurfaceHolder holder, int format, int width,
				int height) {
			// TODO Auto-generated method stub
			
		}
		@Override
		public void surfaceDestroyed(SurfaceHolder holder) {
			// TODO Auto-generated method stub
			mediaPlayer.release();
			
		}*/
}
		
		